package com.zjcode.cdcer.controller;

import com.chinatechstar.component.commons.controller.BaseController;
import com.chinatechstar.component.commons.supports.PageData;
import com.zjcode.cdcer.model.basic.JsonObj;
import com.zjcode.cdcer.service.CerSysteminitImportInfoService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@Slf4j
@RequestMapping("/v1/importFile/")
public class ImportFileController  extends BaseController {


    @Autowired
    private CerSysteminitImportInfoService cerSysteminitImportInfoService;


    // 导入农癌初始数据上报（国家系统来源）
    @PostMapping(value = "/importGJCerSystemDataInit")
    @ApiOperation("导入农癌初始数据上报（国家系统来源）")
    public JsonObj importGJCerSystemDataInit(@RequestParam("file") MultipartFile file, HttpServletResponse response)
            throws IOException {
        log.info("导入农癌初始数据上报（国家系统来源）");
        PageData pageData = getPageData();
        String userId = (String) pageData.get("user");
        return cerSysteminitImportInfoService.importGJCerSystemDataInit(file,response,userId);
//        return JsonObj.success("数据导入成功");
    }

    // 导入农癌初始数据正式库（国家系统来源）
    @PostMapping(value = "/importGJCerSystemDataInitOfficial")
    @ApiOperation("导入农癌初始数据正式库（国家系统来源）")
    public JsonObj importGJCerSystemDataInitOfficial(@RequestParam("file") MultipartFile file, HttpServletResponse response)
            throws IOException {
        log.info("导入农癌初始数据正式库（国家系统来源）");
        PageData pageData = getPageData();
        String userId = (String) pageData.get("user");
        return cerSysteminitImportInfoService.importGJCerSystemDataInitOfficial(file,response,userId);
    }


    // 导入农癌详情数据上报（国家系统来源）
    @PostMapping(value = "/importGJCerDetailData")
    @ApiOperation("导入农癌详情数据上报（国家系统来源）")
    public JsonObj importGJCerDetailData(@RequestParam("file") MultipartFile file, HttpServletResponse response)
            throws IOException {
        log.info("导入农癌详情数据上报（国家系统来源）");
        PageData pageData = getPageData();
        String userId = (String) pageData.get("user");
        return cerSysteminitImportInfoService.importGJCerDetailData(file,response,userId);
    }


    // 导入农癌详情数据正式库（国家系统来源）
    @PostMapping(value = "/importGJCerDetailOfficial")
    @ApiOperation("导入农癌详情数据正式库（国家系统来源）")
    public JsonObj importGJCerDetailOfficial(@RequestParam("file") MultipartFile file, HttpServletResponse response)
            throws IOException {
        log.info("导入农癌详情数据正式库（国家系统来源）");
        PageData pageData = getPageData();
        String userId = (String) pageData.get("user");
        return cerSysteminitImportInfoService.importGJCerDetailOfficial(file,response,userId);
    }



}
